<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>管理平台</title>
    <jsp:include page="../../../include/header.jsp"></jsp:include>
    <style type="text/css">
			table td{
			text-align: center;
			white-space: normal; 
			overflow: hidden;
		    text-overflow: ellipsis;
			}
		 	table th{
			text-align: center;
		 	}
		 	
	</style>
</head>
<body>
<div id="wrapper" class="row">
			<div class="col-lg-12">
				<h1 class="page-header">模板管理</h1>
				<div class="pull-right">
				<div class="btn-group">
						<button type="button"  class="btn btn-success margin-lr" title="新建"  onclick="toAdd()" >
							<i class="fa fa-file-o"></i> 新建
						</button>
						<button type="button"  class="btn btn-success margin-lr" title="刷新" 
							onclick="window.location.reload();">
							<i class="fa fa-refresh"></i> 刷新
						</button>
					</div>
			</div>
			</div>
		<!-- 数据表格 -->
		<div class="col-lg-12 title-top">
			
		<!-- <div class="box-tools pull-right">
				<div class="has-feedback">
					规格名称：<input type="text" name="fspecName" id="fspecName" size="12" placeholder="模板名称"><button class="btn btn-default" onclick="ftoDetail()">查询</button>
				</div>
			</div> -->
		<!--工具栏/-->
			<!--数据列表-->
			<table id="dataList"
				class="table table-bordered table-striped table-hover dataTable">
				<thead>
					<tr>
						<th class="sorting_asc">模板ID</th>
						<th class="sorting">模板名称</th>
						<!-- <th class="sorting">关联种类</th> -->
						<th class="sorting">关联规格</th>
						<th class="sorting">自定义属性</th>
						<th class="text-center">操作</th>
					</tr>
				</thead>
				<tbody>	
					<c:forEach items="${list}" var="Templete">
						<tr>
							<td>${Templete.id }</td>
							<td>${Templete.name }</td>
							<%-- <td>${Templete.categorytwid }</td> --%>
							<td>${Templete.spec }</td>
							<td>
							<button type="button" class="btn btn-success" title="详情"  onclick="toDetail('${Templete.id }')" >详情</button>
							</td>
							<td class="text-center">
								<button type="button" class="btn btn-success" title="新建"  onclick="toEdit('${Templete.id }')" >编辑</button>
								<button type="button" class="btn btn-success" title="删除"  onclick="toDelete('${Templete.id }')">删除</button>
							</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
			<!--数据列表分页--- 需要修改/-->
			<tm-pagination conf="paginationConf"></tm-pagination>
		</div>
		<!-- 数据表格 /-->

</div>
<jsp:include page="../../../include/javascripts.jsp"></jsp:include>
<script type="text/javascript">
    /* 点击新增规格选项 */
$(document).ready(function(){
    $("#addTemplate").click(function(){
    	var tr="<tr><td><input class=\"form-control\" name=\"specName\" placeholder=\"规格选项\">"+
	    	"</td><td><input class=\"form-control\" name=\"specSort\" placeholder=\"排序\">"+
			"</td><td><input type=\"checkbox\" name=\"check\" checked=\"checked\" />"+
			"</td></tr>";
			$("#table").append(tr);
    });
    $("#deleteTemplate").click(function(){
        var check = document.getElementsByName("check");
        for(var i=0;i<check.length;i++){
            if(check[i].checked){
                 document.getElementById('table').deleteRow(i);
                 i--;
            }
        }
    });
})
var addDialog;
function toAdd(){
	addDialog = Kit.dialog("添加","${BASE_PATH}/bus/goods/template/toAdd",{closable:true,size:'size-wide'}).open();		
  }
var editDialog;
function toEdit(id){
	editDialog = Kit.dialog("编辑","${BASE_PATH}/bus/goods/template/toEdit/"+id,{closable:true,size:'size-wide'}).open();		
  }
var DetailDialog;
function toDetail(id){
	DetailDialog = Kit.dialog("详情","${BASE_PATH}/bus/goods/template/toDetail/"+id,{closable:true,size:'size-wide'}).open();	
	
  }
function toDelete(id){
	Kit.confirm("提示","您确定要删除这条数据吗？",function(){
		$.post("${BASE_PATH}/bus/goods/template/doDelete/"+id,function(result){
			if(result.flag==0){
				$("#Templete"+id).remove();
			}else if(result.flag==1){
				Kit.alert("该模板已有商品绑定，禁止删除");return;
			}else {
				Kit.alert("操作失败");return;
			}
			
		});
	});
}
</script>
<script type="text/html" id="thumbTpl">
<a href="javascript:void(0)" onclick="Kit.photo('{{thumb}}')" class="center-block thumbnail thumbnail-none-margin width50"><img src="{{thumb}}"></a>
</script>
<script type="text/html" id="dataTpl">
</script>
</body>
</html>